package demo;

import com.jfinal.config.*;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.template.Engine;
import com.jfinal.server.undertow.UndertowServer;
import demo.controller.StudentController;
import demo.controller.interceptor.LoginInterceptor;
import demo.domain.CourseSelect;
import demo.domain.Student;
import demo.domain.Teacher;

public class DemoConfig extends JFinalConfig {


//    public static void main(String[] args) {
//        UndertowServer.start(DemoConfig.class, 80, true);
//    }

    public void configConstant(Constants me) {
        me.setDevMode(true);
    }

    public void configRoute(Routes me) {
        me.scan("demo.");
    }

    public void configEngine(Engine me) {
      //  me.setDevMode(true);

        // 配置极速模式，性能提升 13%
        me.setFastMode(true);


// jfinal 4.9.02 新增配置：支持中文表达式、中文变量名、中文方法名、中文模板函数名
        me.setChineseExpression(true);
    }
    public void configPlugin(Plugins me) {
        DruidPlugin dp =new DruidPlugin("jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=UTF-8&userSSL=false&serverTimezone=GMT%2B8","root","123456");
        me.add(dp);
        ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
        me.add(arp);
        arp.addMapping("student",Student.class);
        arp.addMapping("teacher", Teacher.class);
        arp.addMapping("course_select", CourseSelect.class);
    }
    public void configInterceptor(Interceptors me) {
        me.addGlobalActionInterceptor(new LoginInterceptor());
    }
    public void configHandler(Handlers me) {}
}